package demo1;

public class Student implements Comparable<Student> {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

//    public int compareTo(Student o) {
//        if (this.age > o.age) {
//            return 1;
//        } else if (this.age == o.age) {
//            return 0;
//        } else {
//            return -1;
//        }
//    }
    public int compareTo(Student o) {//默认一种表现方式
        //return this.age - o.age;//升序
        //return o.age - this.age;//降序
        return o.name.compareTo(this.name);
    }
}


//public class Student {
//    public String name;
//    public int age;
//
//    public Student(String name, int age) {
//        this.name = name;
//        this.age = age;
//    }
//
//    @Override
//    public String toString() {
//        return "Student{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                '}';
//    }
//}
